import java.util.*;
class Stack{
    //栈的实现用数组
    int[]data;
    int size=0;
    int maxSize;
    int top=0;

    public Stack(int maxSize){
        this.data=new int[maxSize];
        this.maxSize=maxSize;
    }

    public void push(int val){
        //若栈的容量大于元素数量
        if(maxSize>size){
            //Push后栈顶元素已经加1，真正的栈顶下标top-1
            data[top++]=val;
            this.size++;
        }else{
            System.out.println("error");
        }
    }
    public void pop(){
        if(this.size==0){

            System.out.println("error");
        }else{
            int a=data[--top];
            System.out.println(a);
            this.size--;
        }


    }
    public void top(){
        if(this.size==0){
            System.out.println("error");
        }else{
            //栈顶下标top-1
            System.out.println(data[top-1]);

        }


    }
}

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.nextLine());//总操作次数
        Stack stack=new Stack(n);

        while(sc.hasNextLine()){
            String str=sc.nextLine();
            String arr[]=str.split(" ");
            if(arr[0].equals("push")){
                stack.push(Integer.parseInt(arr[1]));
            }else if(arr[0].equals("pop")){
                stack.pop();

            }else{
                stack.top();
            }

        }
    }
}



